<?php

$link = mysqli_connect('localhost','root','root','login','3306');
$query = 'select * from newscate';
$ree = mysqli_query($link,$query);

$arr = array();
while($i = mysqli_fetch_assoc($ree))
{
	$arr[] = $i;
}
$brr = getcate($arr);
print_r($brr);

//echo '<select>';
function getcate($arr,$brr = array(),$pid=0,$grade='|')
{
	global $arr;
	$grade = '--'.$grade;
	foreach($arr as $k=>$v)
	{
		if($v['pid']==$pid)
		{
			$arr[$k]['name'] = $grade.$v['name'];
			$brr[$k] = $arr[$k];
			$brr = getcate($arr,$brr,$v['Id'],$grade);
		}
	}
	return $brr;	
}
//echo '</select>';

?>
<meta charset="utf-8">